import random

lst = [random.randint(1,20) for i in range(20)]

d = {}

for i in lst:
    d[i] = d.get(i,0) + 1
print(d)


valsList = sorted(d.values(), reverse=True)
max_num = max(valsList)
sec_num = max_num - 1  # 这里的逻辑不对吧
thi_num = max_num - 2

print(max_num)
print(sec_num)
print(thi_num)

for item in d.items():
    if item[1] == max_num:
        print('出现次数最多的前1个数字:%s 次数为%s' %(item[0], item[1]))
    if item[1] == sec_num:
        print('出现次数最多的前2个数字:%s 次数为%s' %(item[0], item[1]))
    if item[1] == thi_num:
        print('出现次数最多的前3个数字:%s 次数为%s' %(item[0], item[1]))
